package com.urguxxi.springdemo.util;

import com.urguxxi.springdemo.entity.Admin;
import org.springframework.validation.BindingResult;
import org.springframework.validation.ObjectError;
import org.springframework.validation.annotation.Validated;

import javax.servlet.http.HttpSession;
import java.util.List;

public class ValidatorUil {
    /**
     * 数据校验
     * 展示错误信息
     */
//    public static void login(@Validated Admin admin,BindingResult bindingResult, HttpSession session) throws Exception{
//        ValidatorUil.showMsg(bindingResult);
//        return LoginService login(admin,bindingResult,session);
//    }
    public static void showMsg(BindingResult bindingResult)throws Exception{
        List<ObjectError> allErrors = bindingResult.getAllErrors();
        for (ObjectError error: allErrors){
            throw new Exception(error.getDefaultMessage());
        }
    }

}
